import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { Form, Input, Button, Card, message } from 'antd';

const FormItem = Form.Item;

@connect()
@Form.create()
export default class AddRole extends PureComponent {
  state = {
  }
  componentDidMount() {
    console.log('componentDidMount');
  }
  /*
    处理表单数据
   */
  handleSubmit = (e) => {
    e.preventDefault();
    this.props.form.validateFieldsAndScroll((err, values) => {
      if (!err) {
        console.log('Received values of form: ', values);
        /*
          成功后调用表单清除
         */
        message.success('SUCCESS');
        this.props.form.resetFields();
      }
    });
  }
  render() {
    const { getFieldDecorator } = this.props.form;
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 12 },
        md: { span: 10 },
      },
    };
    const tailFormItemLayout = {
      wrapperCol: {
        xs: {
          span: 24,
          offset: 0,
        },
        sm: {
          span: 16,
          offset: 8,
        },
      },
    };
    return (
      <Card bordered={false}>
        <Form onSubmit={this.handleSubmit}>
          <FormItem
            {...formItemLayout}
            label="角色名"
          >
            {getFieldDecorator('roleName', {
              rules: [
                {
                  required: true, message: '请输入角色名',
                }],
            })(
              <Input placeholder="请输入角色名" />
            )}
          </FormItem>
          <FormItem {...tailFormItemLayout}>
            <Button type="primary" htmlType="submit">保存</Button>
          </FormItem>
        </Form>
      </Card>
    );
  }
}
